$(function() {
	var opts_long = {lang:'<?php echo $_GET['l'] ?>',styleWithCSS:true,cssfiles:['includes/wysiwyg/css/textarea.css'],height:250,toolbar:'maxi',fmOpen:function(callback){$('<div id="myelfinder" />').elfinder({url:'includes/wysiwyg/connector.php',lang : '<?php echo $_GET['l'] ?>',dialog:{width:700,modal:true,title:'Dateimanager'},closeOnEditorCallback:true,editorCallback:callback});}
	}
	var opts_short = {lang:'<?php echo $_GET['l'] ?>',styleWithCSS:true,cssfiles:['includes/wysiwyg/css/textarea.css'],height:150,toolbar:'maxi',fmOpen:function(callback){$('<div id="myelfinder_short" />').elfinder({url:'includes/wysiwyg/connector.php',lang : '<?php echo $_GET['l'] ?>',dialog:{width:700,modal:true,title:'Dateimanager'},closeOnEditorCallback:true,editorCallback:callback});}
	}
	$('#config').tabs({
		fx:{opacity:'toggle'},
		select: function(event, ui){
			var tabName = ui.panel.id;
			$('input#hidden_tab').val(tabName);
			window.location.hash = tabName;
			if (tabName == 'desc') {
				$('#tabs').tabs({fx:{opacity:'toggle'},
					show: function(event, ui){
						var lId = ui.panel.id.substring(9);
		        		setTimeout(function(){$('#products_description_'+lId).elrte(opts_long);},500);
						setTimeout(function(){$('#products_short_description_'+lId).elrte(opts_short);},800);
					},
					select: function(event, ui){
						var lId = ui.panel.id.substring(9);
						setTimeout(function(){$('#products_description_'+lId).elrte(opts_long);},500);
						setTimeout(function(){$('#products_short_description_'+lId).elrte(opts_short);},800);
					}
				});
    		}else if(tabName == 'misc'){
    			$('#staffelpreise').tabs({fx:{opacity:'toggle'}});
    			var accordionLeft=$("#product_misc_left");var indexLeft=$.cookie("accordion_left");var activeLeft;if(indexLeft!==null){activeLeft=accordionLeft.find("h3:eq("+indexLeft+")");}else{activeLeft = 0;}accordionLeft.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeLeft,change:function(event, ui){var indexLeft = $(this).find("h3").index(ui.newHeader[0]);$.cookie("accordion_left",indexLeft,{path:"/"});}});var accordionRight=$("#product_misc_right");var indexRight = $.cookie("accordion_right");var activeRight;if(indexRight!==null){activeRight=accordionRight.find("h3:eq("+indexRight+")");}else{activeRight = 0;}accordionRight.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeRight,change:function(event,ui){var indexRight=$(this).find("h3").index(ui.newHeader[0]);$.cookie("accordion_right",indexRight,{path:"/"});}});
    			<?php if(isset($_GET['pid']) && !empty($_GET['pid'])) { ?>
					xajax_firstLoad(<?php echo $_GET['pid'] ?>);
					
				<?php } ?>
    		}else if(tabName == 'img'){
    			xajax_FirstImg(<?php echo $_GET['pid'] ?>);
    			$('.get_img_url').live('click', function(){
    				xajax_getURLPreview($('.img_url').val(),$('input[name=products_id]').val());
    			});
    		}else if(tabName == 'attr'){
    			xajax_getOverview(<?php echo $_GET['pid'] ?>);
    		}else if(tabName == 'filt'){
    			<?php if(isset($_GET['pid']) && !empty($_GET['pid'])) { ?>
    				xajax_getFilter(<?php echo $_GET['pid'] ?>);
    			<?php } ?>
    		}else if(tabName == 'google'){
    			if($('#selection').length > 0)
    				xajax_get_exist_url(<?php echo $_GET['pid'] ?>);
    		}
    	},
    	show: function(event, ui){
			var tabName = ui.panel.id;
			$('input#hidden_tab').val(tabName);
			window.location.hash = tabName;
			if (tabName == 'desc') {
				$('#tabs').tabs({fx:{opacity:'toggle'},
					show: function(event, ui){
						var lId = ui.panel.id.substring(9);
						setTimeout(function(){$('#products_description_'+lId).elrte(opts_long);},500);
						setTimeout(function(){$('#products_short_description_'+lId).elrte(opts_short);},800);
					},
					select: function(event, ui){
						var lId = ui.panel.id.substring(9);
						setTimeout(function(){$('#products_description_'+lId).elrte(opts_long);},500);
						setTimeout(function(){$('#products_short_description_'+lId).elrte(opts_short);},800);
					}
				});
    		} else if(tabName == 'misc') {
    			$('#staffelpreise').tabs({fx:{opacity:'toggle'}});
    			var accordionLeft=$("#product_misc_left");var indexLeft=$.cookie("accordion_left");var activeLeft;if(indexLeft!==null){activeLeft=accordionLeft.find("h3:eq("+indexLeft+")");}else{activeLeft = 0;}accordionLeft.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeLeft,change:function(event, ui){var indexLeft = $(this).find("h3").index(ui.newHeader[0]);$.cookie("accordion_left",indexLeft,{path:"/"});}});var accordionRight=$("#product_misc_right");var indexRight = $.cookie("accordion_right");var activeRight;if(indexRight!==null){activeRight=accordionRight.find("h3:eq("+indexRight+")");}else{activeRight = 0;}accordionRight.accordion({header:"h3",fx:{opacity:'toggle'},autoHeight:false,active:activeRight,change:function(event,ui){var indexRight=$(this).find("h3").index(ui.newHeader[0]);$.cookie("accordion_right",indexRight,{path:"/"});}});
    			<?php if(isset($_GET['pid']) && !empty($_GET['pid'])) { ?>
					xajax_firstLoad(<?php echo $_GET['pid'] ?>);
				<?php } ?>
    		}else if(tabName == 'img'){
    			xajax_FirstImg(<?php echo $_GET['pid'] ?>);
    			$('.get_img_url').live('click', function(){
    				xajax_getURLPreview($('.img_url').val(),$('input[name=products_id]').val());
    			});
    		}else if(tabName == 'attr'){
    			xajax_getOverview(<?php echo $_GET['pid'] ?>);
    		}else if(tabName == 'filt'){
    			<?php if(isset($_GET['pid']) && !empty($_GET['pid'])) { ?>
    				xajax_getFilter(<?php echo $_GET['pid'] ?>);
    			<?php } ?>
    		}else if(tabName == 'google'){
    			xajax_get_exist_url(<?php echo $_GET['pid'] ?>);
    		}
    	}
	});
	$('.products_data').fadeIn();
	$('#dialog_box').dialog({autoOpen:false,show:"fade",hide:"explode",width:600,height: 350,modal:true,position:['center', 'center']});
	$('.dialog_button').live('click',function(){$("#dialog_box").load($(this).attr('href')).dialog('open');return false;});
	
	var checkFSK = $('input[name=products_fsk18]:checked').val();
	if(checkFSK == '1'){$('.usk_dropdown').fadeIn();}
	
	$('input[name=products_fsk18]').click(function(){if($(this).val()==1){$('.usk_dropdown').fadeIn();}else{$('.usk_dropdown').hide();}});
	xajax_checkCategory();
});

function set_editor(){var options_additional={styleWithCSS:false,cssfiles:['includes/wysiwyg/css/textarea.css'],allowSource:false,height:150,toolbar:'mini',fmOpen:function(callback){$('<div id=\"myelfinder_add\" />').elfinder({url:'includes/wysiwyg/connector.php',dialog:{width:700,modal:true,title:'Dateimanager'},closeOnEditorCallback:true,editorCallback:callback});}}
$('#products_additional_description').elrte(options_additional);$('.panel-save').hide();}

function get_values(action) {var content=$('#products_additional_description').elrte('val');var title=$('.products_additional_title').val();if(content !='' && title !=''){if(action == 'new')xajax_save_new_additional(title,content,$('.lng_id').val(),$('input[name=products_id]').val());else xajax_save_edit_additional(title,content,$('.lng_id').val(),$('input[name=products_id]').val(),$('.add_id').val());$('#dialog_box').dialog('close');} else alert('Sie dürfen keines der beiden Felder leer lassen.');}